//1  范型与继承
// 例子：
// 写法一：
// interface T {
//   length: number,
// }
// interface childT extends T {
//    name: string,
//  }
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
// 写法二：
// type aT = {
//   length: number,
// };
// type bT = {
//   name: string,
// };
// type T = aT & bT;
// (1)
function getLen(args) {
    return args.length;
}
;
// console.log(getLen('hello'));
// console.log(getLen([1, 2, 3]));
// (2)
function getLen2(args) {
    return args.length;
}
;
function getLen3(args) {
    return args.length;
}
;
function getLen4(args) {
    return args.length;
}
;
console.log(getLen4('hello22222'));
console.log(getLen4([1, 2, 3]));
//2 范型与类
// 写法一：
var UserCls = /** @class */ (function () {
    function UserCls() {
        this.data = [];
    }
    ;
    UserCls.prototype.addUer = function (user) {
        this.data.push(user);
        return true;
    };
    ;
    UserCls.prototype.getOne = function () {
        return this.data.shift();
    };
    ;
    UserCls.prototype.showall = function () {
        return this.data;
    };
    return UserCls;
}());
;
var instance = new UserCls();
instance.addUer({
    name: 'zml',
    age: 34,
    sex: 1,
});
instance.addUer({
    name: 'xiaoh',
    age: 39,
    sex: 0,
});
// console.log(instance.getOne());
// console.log(instance.showall());
// 写法二：
var User2 = /** @class */ (function () {
    function User2(data) {
        this.data = data;
    }
    ;
    User2.prototype.adduser = function () {
        var _a;
        var users = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            users[_i] = arguments[_i];
        }
        (_a = this.data).push.apply(_a, users);
        return true;
    };
    ;
    User2.prototype.showUsers = function () {
        return this.data;
    };
    return User2;
}());
var instance2 = new User2([]);
instance2.adduser({
    name: 'swk',
    age: 800,
}, {
    name: 'zbj',
    age: 600,
});
console.log(instance2.showUsers());
// 父类
var ParentCls = /** @class */ (function () {
    function ParentCls(user) {
        this.name = 'initName';
        this.age = 0;
        this.sex = 0;
        this.name = user.name;
        this.age = user.age;
        this.sex = user.sex;
        '';
    }
    ParentCls.prototype.info = function () {
        return "\u6211\u662F".concat(this.name, "\u4ECA\u5E74").concat(this.age, "\u5C81\uFF0C\u662F\u4E2A").concat(this.sex ? '男' : '女', "\u5B69\u5B50");
    };
    ;
    ParentCls.prototype.getInfo = function () {
        return this.info();
    };
    ;
    ParentCls.prototype._setSex = function (sex) {
        this.sex = sex;
    };
    ;
    ParentCls.prototype._getSex = function (sex) {
        return this.sex;
    };
    ;
    return ParentCls;
}());
var person1 = new ParentCls({
    name: 'zhanhgsan',
    age: 23,
    sex: 1,
});
// console.log(person1.getInfo());
//子类
var ChildCls = /** @class */ (function (_super) {
    __extends(ChildCls, _super);
    function ChildCls(user) {
        var _this = _super.call(this, user) || this;
        _this.name = user.name;
        _this.age = user.age;
        _super.prototype._setSex.call(_this, user.sex);
        return _this;
    }
    ;
    ChildCls.prototype.childMethods = function () {
        return 'childMethod';
    };
    ;
    return ChildCls;
}(ParentCls));
;
var person2 = new ChildCls({
    name: 'wuwu',
    age: 65,
    sex: 0,
});
console.log(person2.getInfo());
console.log(person2.childMethods());
//5 类的修饰符--readonly妙用
// 该属性只读无法修改，但是可以在改造函数中修改
var Axios = /** @class */ (function () {
    function Axios(site) {
        this.site = 'www.baidu.com';
        this.site = site || this.site;
    }
    Axios.prototype.getUrl = function () {
        return "\u60A8\u8BF7\u6C42\u7684\u989D\u5730\u5740\u662F\uFF1A".concat(this.site);
    };
    return Axios;
}());
;
var axios = new Axios('www.chaojin.cn');
// axios.site = 'www.chaojin.cn';
console.log(axios.getUrl());
// 6.static静态属性
// 单例实现
var Axios2 = /** @class */ (function () {
    function Axios2() {
        console.log('构造函数');
    }
    ;
    Axios2.make = function () {
        if (!Axios2.instance) {
            Axios2.instance = new Axios2();
        }
        ;
        return Axios2.instance;
    };
    ;
    Axios2.instance = null;
    return Axios2;
}());
var axios2 = Axios2.make();
var axios22 = Axios2.make();
var Test2 = /** @class */ (function () {
    function Test2() {
        var list = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            list[_i] = arguments[_i];
        }
        this._lists = [];
        this._lists = list;
    }
    ;
    Object.defineProperty(Test2.prototype, "lists", {
        get: function () {
            console.log('get------');
            return this._lists[this._lists.length - 1];
        },
        set: function (val) {
            console.log('set------');
            this._lists.push(val);
        },
        enumerable: false,
        configurable: true
    });
    ;
    return Test2;
}());
var testInstance2 = new Test2({ name: 'zhang1', checked: false });
testInstance2.lists = { name: 'zhang2', checked: true };
console.log(testInstance2.lists);
// 8.抽象类
var Common = /** @class */ (function () {
    function Common() {
    }
    Common.prototype.setName = function (name) {
        this.name = name;
        return this.name;
    };
    return Common;
}());
var child1 = /** @class */ (function (_super) {
    __extends(child1, _super);
    function child1() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    child1.prototype.getName = function () {
        return this.name;
    };
    ;
    return child1;
}(Common));
var instance3 = new child1();
console.log(instance3.setName('小名'));
// 9.抽象类和接口混合使用
var common2 = /** @class */ (function () {
    function common2() {
    }
    common2.prototype.set = function (sex) {
        console.log('设置sex：', sex);
    };
    ;
    return common2;
}());
var Color;
(function (Color) {
    Color[Color["red"] = 0] = "red";
    Color[Color["agreen"] = 1] = "agreen";
    Color[Color["blue"] = 2] = "blue";
})(Color || (Color = {}));
;
var child2 = /** @class */ (function (_super) {
    __extends(child2, _super);
    function child2() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    child2.prototype.get = function () {
        console.log('child2---get');
    };
    ;
    return child2;
}(common2));
var instance4 = new child2();
instance4.get();
instance4.set(1);
